<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        /* 弹性盒子 */
        .box{
            width: 300px;
            height: 300px;
            background: aqua;
            display: flex;
            justify-content: center;
            align-items: center;

        }
        .div1{
            width: 150px;
            height: 150px;
            background: salmon;
            line-height: 150px;
            text-align: center;
            color: aliceblue;
        }
        /* 定位 */
        .box2{
            width: 300px;
            height: 300px;
            background: aqua;
            position: relative;

        }
        .div2{
            width: 150px;
            height: 150px;
            background: salmon;
            line-height: 150px;
            text-align: center;
            color: aliceblue;
            position: absolute;
            top:0;
            left:0;
            right:0;
            bottom:0;
            margin:auto; 
        }
        /* 定位 */
        .box3{
            width: 300px;
            height: 300px;
            background: aqua;
            position: relative;

        }
        .div3{
            width: 150px;
            height: 150px;
            background: salmon;
            line-height: 150px;
            text-align: center;
            color: aliceblue;
            position: absolute;
            top: 50%;
            left: 50%;
            transform:translate(-50%,-50%)
        }
    </style>
</head>
<body>
    <!-- 弹性盒子 -->
    <div class="box">
        <div class="div1">
            弹性盒子
        </div>
    </div>
    <br>
    <!-- 夫相子随 -->
    <div class="box2">
        <div class="div2">
            夫相子随
        </div>
    </div>
    <br>
    <!-- 定位 -->
    <div class="box3">
            <div class="div3">
                定位
            </div>
        </div>
</body>
</html>